package xyz.iguilty.workflow.core.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import xyz.iguilty.workflow.constant.ProcessConstants;
import xyz.iguilty.workflow.enums.ProcessLog;
import xyz.iguilty.workflow.model.*;

public abstract class AbstractActivity<Model extends BusinessModel,ID> extends AnnotationBeanNameGenerator {

    @Autowired
    protected WorkFlowIdentityService workFlowIdentityService;


    public String getStatusAfterCreated(){
        return "待处理";
    }

    public String getStatusAfterClaimed(){
        return "处理中";
    }

    public String getStatusAfterCompleted(){
        return "已完成";
    }

    /**
     * 获得当前环节的负责人
     * @return
     */
    public ActorModel getCurrentActors(ActivityContext context){
        return null;
    }

    @Deprecated
    public NextActors assignActor(){
        return null;
    }

    public abstract String currentActivityKey();

    @Override
    public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
        String beanName = super.generateBeanName(definition, registry);
        return this.currentActivityKey()==null?beanName:this.currentActivityKey();
    }

    public DealResult restart(TaskForm form){
        return DealResult.create(ProcessLog.RESTART).addVariable(ProcessConstants.INITIATOR,"");
    }

    public DealResult pass(TaskForm form){
        return DealResult.create(ProcessLog.PASS);
    }

    public DealResult rollback(TaskForm form){
        return DealResult.create(ProcessLog.ROLLBACK);
    }

    public DealResult reject(TaskForm form){
        return DealResult.create(ProcessLog.REJECT);
    }

    public DealResult deal(TaskForm form){
        return DealResult.create(ProcessLog.DEAL);
    }
}
